<?php
if (!defined('IN_XLP')) {
    exit('Access Denied');
}
$Document = array(
    'pageid' => 'home-stat', //页面标示
    'pagename' => '问卷调查统计', //当前页面名称
    'mycss' => array(), //加载的css样式表
    'myjs' => array('content/Chart.min'), //加载的js脚本
    'footerjs' => array(),
    'head' => true, //加载头部文件
);

include getTpl('header', 'public');
?>
<!--顶部导航 开始-->
<?php include getTpl('top', 'public'); ?>
<!--顶部导航 结束-->
<!--左侧菜单 开始-->
<?php include getTpl('nav', 'public'); ?>
<!--左侧菜单 结束-->
<!--主体 开始-->
<!-- content -->

<section id="content">
    <section class="main padder">
        <div class="clearfix">

            <h4><i class="fa fa-table"></i><?php echo $Document['pagename']?></h4>
        </div>
        <!--0-->

        <!--0--> 
        <!--1-->
        <div class="row">
            <div class="col-md-4">
                <section class="panel">
                    <div class="panel-body">
                        <div style="height:220px"> 
                            <!---->
                            <div style="margin:0; float:left; width:40%">
                                <p>人数统计</p>
                                <br/>
                                <p>总人数：<?php echo $total; ?></p>
                                <p>男：<span style=" color:#ff3333;"><?php echo $sex['1']; ?>人</span>&nbsp;<?php echo ceil(($sex['1'] / $total) * 100) . '%'; ?></p>
                                <p>女：<span style=" color:#ff3333;"><?php echo $sex['2']; ?>人</span>&nbsp;<?php echo ceil(($sex['2'] / $total) * 100) . '%'; ?></p>
                                <p>未知：<span style=" color:#ff3333;"><?php echo $sex['0']; ?>人</span>&nbsp;<?php echo ceil(($sex['0'] / $total) * 100) . '%'; ?></p>
                            </div>
                            <div style="float:right; position:relative;">
                                <canvas id="chart" width="200" height="200"/>
                            </div>
                            <!----> 
                        </div>
                    </div>
                </section>
            </div>
            <?php
            foreach ($exam as $ek => $ev) {
                if ($ev['check'] == 1) {
                    ?>  
                    <div class="col-md-4">
                        <section class="panel">
                            <div class="panel-body">
                                <div style="height:250px; overflow-y: scroll;"> 
                                    <!---->
                                    <div style="margin:0">
                                        <p><?php echo $ev['title']; ?></p>
                                        <div style="float:right; position:relative;"> 
                                            <canvas id="chart<?php echo $ek + 1; ?>" width="500" height="500">
                                            </canvas></div>
                                    </div>
                                    <!----> 
                                </div>
                            </div>
                        </section>
                    </div>
                    <?php
                } else {
                    ?>  
                    <div class="col-md-4">
                        <section class="panel">
                            <div class="panel-body">
                                <div style="height:220px"> 
                                    <!---->
                                    <div style="margin:0; float:left; width:40%">
                                        <p><?php echo $ev['title']; ?></p>
                                        <br/>
                                        <?php
                                        foreach ($ev as $eek => $eev) {
                                            if ($eek != 'title' && $eek != 'stat') {
                                                ?>
                                                <p><?php echo $eek; ?>、<?php echo $eev; ?>&nbsp;&nbsp;<span style=" color:#ff3333;"><?php echo $ev['stat'][$eek]; ?>人</span>&nbsp;&nbsp;<?php echo ceil(($ev['stat'][$eek] / $total) * 100) . '%'; ?></p>
                                                <?php
                                            }
                                        }
                                        ?>
                                    </div>
                                    <div style="float:right; position:relative;">
                                        <canvas id="chart<?php echo $ek + 1; ?>" width="200" height="200"/>
                                    </div>
                                    <!----> 
                                </div>
                            </div>
                        </section>
                    </div>
                    <?php
                }
            }
            ?> 
        </div>
        <!--1--> 

    </section>
    <!--/ main padder --> 
</section>
<!--/ content --> 
<!--主体 结束--> 
<script>
    var color = [{"color": "#F7464A", "highlight": "#FF5A5E"},
        {"color": "#46BFBD", "highlight": "#5AD3D1"},
        {"color": "#FDB45C", "highlight": "#FFC870"},
        {"color": "#949FB1", "highlight": "#A8B3C5"},
        {"color": "#4D5360", "highlight": "#626979"},
        {"color": "#4D5360", "highlight": "#626979"},
        {"color": "#4D5360", "highlight": "#626979"},
        {"color": "#4D5360", "highlight": "#626979"}, ];
    /*
     var doughnutData1 = [
     {
     value: <?php echo 1; ?>,
     color: "#F7464A",
     highlight: "#FF5A5E",
     label: "文本"
     },
     {
     value: <?php echo 2; ?>,
     color: "#46BFBD",
     highlight: "#5AD3D1",
     label: "菜单"
     }
     
     ];
     */
    //alert(color[1]["color"]);
    var doughnutData = [
        {value: <?php echo $sex['1']; ?>, color: color[0]["color"], highlight: color[0]["highlight"], label: "男"},
        {value: <?php echo $sex['2']; ?>, color: color[1]["color"], highlight: color[1]["highlight"], label: "女"},
        {value: <?php echo $sex['0']; ?>, color: color[2]["color"], highlight: color[2]["highlight"], label: "未知"},
    ];

<?php
foreach ($exam as $ek => $ev) {

    if ($ev['check'] == 1) {
        $labels = '';
        $datasets_data = '';
        foreach ($ev as $eek => $eev) {
            if ($eek != 'title' && $eek != 'stat' && $eek != 'check') {
                $labels.='"' . $eev . '",';
                $datasets_data.=$ev['stat'][$eek] . ',';
            }
        }
        ?>
            var barChartData<?php echo $ek + 1; ?> = {
                labels: [<?php echo $labels; ?>],
                datasets: [
                    {
                        fillColor: "rgba(151,187,205,0.5)",
                        strokeColor: "rgba(151,187,205,0.8)",
                        highlightFill: "rgba(151,187,205,0.75)",
                        highlightStroke: "rgba(151,187,205,1)",
                        scaleOverlay: false,
                        data: [<?php echo $datasets_data; ?>]
                    }
                ]

            }
        <?php
    } else {
        ?>
            var doughnutData<?php echo $ek + 1; ?> = [
        <?php
        $cid = 0;
        foreach ($ev as $eek => $eev) {

            if ($eek != 'title' && $eek != 'stat' && $eek != 'check') {
                ?>
                        {value: <?php echo $ev['stat'][$eek]; ?>, color: color[<?php echo $cid; ?>]["color"], highlight: color[<?php echo $cid; ?>]["highlight"], label: "<?php echo $eev; ?>"},
                <?php
                $cid++;
            }
        }
        ?>


            ];
        <?php
    }
}
?>
    window.onload = function() {
        var ctx = document.getElementById("chart").getContext("2d");
        window.myDoughnut = new Chart(ctx).Doughnut(doughnutData, {responsive: true});
<?php
foreach ($exam as $ek => $ev) {
    if ($ev['check'] == 1) {
        ?>
                var ctx<?php echo $ek + 1; ?> = document.getElementById("chart<?php echo $ek + 1; ?>").getContext("2d");
                window.myBar = new Chart(ctx<?php echo $ek + 1; ?>).Bar(barChartData<?php echo $ek + 1; ?>, {
                    responsive: true
                });
        <?php
    } else {
        ?>
                var ctx<?php echo $ek + 1; ?> = document.getElementById("chart<?php echo $ek + 1; ?>").getContext("2d");
                window.myDoughnut<?php echo $ek + 1; ?> = new Chart(ctx<?php echo $ek + 1; ?>).Doughnut(doughnutData<?php echo $ek + 1; ?>, {responsive: true});
        <?php
    }
}
?>

    };
    $(function() {

    })
</script>
<?php
include getTpl('footer', 'public');
?>
